package com.wit.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.wit.po.Insurancedef;
import com.wit.po.Project;
import com.wit.service.InsurancedefService;
import com.wit.service.ProjectService;
import com.wit.service.impl.InsurancedefServiceImpl;
import com.wit.service.impl.ProjectServiceImpl;

@Controller  
@Scope(value="prototype") 
public class ProjectAction extends ActionSupport{
	
	private ProjectService projectService;
	
	private InsurancedefService insurancedefService;
	
	private Project project;
	
	private Integer insuranceId;

	public Integer getInsuranceId() {
		return insuranceId;
	}

	public void setInsuranceId(Integer insuranceId) {
		this.insuranceId = insuranceId;
	}

	public ProjectService getProjectService() {
		return projectService;
	}

	public void setProjectService(ProjectService projectService) {
		this.projectService = projectService;
	}

	public InsurancedefService getInsurancedefService() {
		return insurancedefService;
	}

	public void setInsurancedefService(InsurancedefService insurancedefService) {
		this.insurancedefService = insurancedefService;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
	
	public String addProject(){
		System.out.println("in find insurancedef................." + insuranceId);
		Insurancedef insurancedef =  insurancedefService.findInsurancedefByIdenfier(insuranceId);
		project.setInsurancedef(insurancedef);
		projectService.addProject(project);
		project = projectService.findProjectByIdenfier(project.getProjectNum());
		insuranceId =  project.getInsurancedef().getInsuranceId();
		return "listPage";
	}
	
	public String modifyProject(){
		projectService.modifyProject(project);
		project = projectService.findProjectByIdenfier(project.getProjectNum());
		insuranceId =  project.getInsurancedef().getInsuranceId();
		return "listPage";
	}
	
	public String deleteProject(){
		project = projectService.findProjectByIdenfier(project.getProjectNum());
		insuranceId = project.getInsurancedef().getInsuranceId();
		projectService.deleteProject(project);
		return "listPage";
	}
	
	public String findProject(){
		project = projectService.findProjectByIdenfier(project.getProjectNum());
		return "editPage";
	}
}
